package com.shop.appcontroller.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.filter.OncePerRequestFilter;

public class LoginFilter extends OncePerRequestFilter {
	protected void doFilterInternal(
			HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
			throws ServletException, IOException {
//		String user=request.getSession().getAttribute("userName").toString();
		if (request.getSession().getAttribute("userName") == null) {
		request.getRequestDispatcher("/ebpplogin.htm").forward(request, response);

		}
		filterChain.doFilter(request, response);
	}
	/**
	 * 创建登陆url链接.
	 * 
	 * @param request
	 * @return
	 */
//	private String buildBackUrl(final HttpServletRequest request) {
//		StringBuffer result = new StringBuffer("http://"
//				+ request.getServerName());
//		if (80 != request.getServerPort()) {
//			result.append(":").append(request.getServerPort());
//		}
//		result.append(request.getContextPath());
//		result.append("/ebpplogin.htm" );
//		return result.toString();
//	}
}
